package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: homechen
 * Date: 2024-03-09
 * Time: 22:50
 */
public class ThreadDemo1 {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();
        new Thread(() -> {
            try {
                System.out.println("wait 之前!");
                lock.wait(); // 这里如果不搭配 synchronized 使用会报错
                System.out.println("wait 之后!");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).start();

        Thread.sleep(1000); // sleep 可以单独使用
        System.out.println("notify 之前!");
        lock.notify();
    }
}
